<?php

namespace app\speedDating\model;

use app\speedDating\model\traits\SimpleModel;
use think\Model;

class SddFinanceAccountLog extends Model
{

    use SimpleModel;

    protected $connection = 'mysql';

    protected $pk = 'id';

    protected $name = 'sdd_finance_account_log';

    protected static $createTimeField = 'gmt_create';

    protected static $updateTimeField = 'gmt_modified';

    /**
     * @see SimpleModel
     * @var string[] 字段数组
     */
    protected static $SimpleMainField = ['*'];

    protected static $selectResultDateTimeFieldParse = ['operate_time', 'gmt_create', 'gmt_modified'];


    /**
     * 查询账户的所有记录
     * @param $size
     * @param $page
     * @param $userID
     * @return SimpleModel[]|array|\think\Collection|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getAllTypeAccountLogByUserID($size, $page, $userID)
    {
        $accountIDs = SddFinanceAccount::field('id')
            ->where('user_id', $userID)
            ->select()->column('id');

        $where = function ($query) use ($accountIDs) {
            $query->where('account_id', 'in', $accountIDs);
        };

        return self::getSimpleMainList($size, $page, $where);
    }
}

